import { _decorator, sys } from 'cc';

import { SS_AudioManager } from '../Manager/SS_AudioManager';
import { Consts } from './Consts';

export class SS_Settings {
    static curMusicV
    static curVibrate

    static InitSettings() {
        let str2 = sys.localStorage.getItem(`${Consts.GAME_NAME}_settings`);
        if (str2) {
            let settings = JSON.parse(str2);

            SS_Settings.curMusicV = settings.music;
            SS_Settings.curVibrate = settings.vibrate;
        } else {
            SS_Settings.curMusicV = 1;
            SS_Settings.curVibrate = 1;
            SS_Settings.saveVolumeData();
        }

        SS_AudioManager.Instance.AudioSource_bgm.volume = SS_Settings.curMusicV;
        SS_AudioManager.Instance.AudioSource_effect.volume = SS_Settings.curMusicV;
    }

    static saveVolumeData() {
        let volume = {
            music: SS_Settings.curMusicV,
            vibrate: SS_Settings.curVibrate,
        }
        sys.localStorage.setItem(`${Consts.GAME_NAME}_settings`, JSON.stringify(volume));
    }

    static InitCollision() {
        {
            // // 获取碰撞检测系统：
            // let manager = director.getCollisionManager();
            // // 默认碰撞检测系统是禁用的，如果需要使用则需要以下方法开启碰撞检测系统：
            // manager.enabled = true;
            // // 默认碰撞检测系统的 debug 绘制是禁用的，如果需要使用则需要以下方法开启 debug 绘制：
            // manager.enabledDebugDraw = true;
        }
    }
}

/** 调试 */
window["SS_Settings"] = SS_Settings;